"""
Celery配置和初始化
"""
from celery import Celery
from utils.config import config

# 创建Celery应用
celery_app = Celery(
    "payment_tasks",
    broker=config.CELERY_BROKER_URL,
    backend=config.CELERY_RESULT_BACKEND,
    include=["tasks.payment_tasks"]  # 包含任务模块
)

# Celery配置
celery_app.conf.update(
    task_serializer="json",
    accept_content=["json"],
    result_serializer="json",
    timezone="Asia/Shanghai",
    enable_utc=True,
    task_track_started=True,
    task_time_limit=30 * 60,  # 任务超时时间30分钟
    task_soft_time_limit=25 * 60,  # 软超时时间25分钟
    worker_prefetch_multiplier=1,  # 预取任务数
    worker_max_tasks_per_child=1000,  # 每个worker最多处理1000个任务后重启
)



